import random
import pgzrun

WIDTH = 720
HEIGHT = 720
board = [[0 for r in range(9)] for c in range(9)]
single = [c+1 for c in range(9)]

def row_up(board):
    return board[1:]+[board[0]]

def row_down(board):
    return [board[-1]]+board[:-1]

def row_left(board):
    return [row_up(x) for x in board]

def row_right(board):
    return [row_down(x) for x in board]

def put_palace(single, x, y):
    global board
    for i in range(x, x+3):
        for j in range(y, y+3):
            board[i][j] = single[i-x][j-y]

def make_board(single):
    global board
    random.shuffle(single)
    single = [[single[0], single[1], single[2]],
              [single[3], single[4], single[5]],
              [single[6], single[7], single[8]]]
    singles = [i for i in range(0, 9)]
    singles[1] = row_right(single)
    singles[7] = row_left(single)
    singles[5] = row_down(single)
    singles[3] = row_up(single)
    singles[0] = row_up(singles[1])
    singles[6] = row_down(singles[7])
    singles[2] = row_down(singles[1])
    singles[8] = row_up(singles[7])
    singles[4] = single[:]
    for i in range(0, 7, 3):
        for j in range(0, 7, 3):
            put_palace(singles[i//3*3+j//3], i, j)

def make_ques(board):
    for i in range(9):
        for j in range(9):
            if random.randint(0, 1):
                board[i][j] = 0
    return board

make_board(single)
board = make_ques(board)
for i in board:
    print(i)

nums = []
offset = 1
num_size = 80
for i in range(9):
    for j in range(9):
        n = board[i][j]
        r = i % 10
        c = j % 10
        num = Actor(str(n))
        num.pos = r * num_size + num_size / 2 + \
            offset, c * num_size + num_size / 2 + offset
        nums.append(num)

def update():
    pass

def draw():
    screen.clear()
    for n in nums:
        n.draw()

pgzrun.go()
